<?php
class Forgot_model extends CI_Model {
	
	public function get_forgot($change_key)
	{
		$sql = 'SELECT * FROM forgot WHERE changeKey=? LIMIT 1';
		$query = $this->db->query($sql, array($change_key));	
		
		return $query->num_rows > 0 ? $query->row() : false;
	}
	
	public function add_forgot($mail, $change_key)
	{
		$sql = 'INSERT INTO forgot (mail, changeKey, applyTime, expireTime) VALUES (?, ?, now(), ?)';
		$expired_time = date("Y-m-d H:i:s", mktime(date("H"), date("i") + 15, date("s"), date("m"), date("d"), date("Y")));
		$query = $this->db->query($sql, array($mail, $change_key, $expired_time));

		return $this->db->affected_rows() > 0;
	}
	
	public function del_forgot($mail)
	{
		$sql = 'DELETE FROM forgot WHERE mail=?';
		$query = $this->db->query($sql, array($mail));
		
		return $this->db->affected_rows() > 0;
	}
}
?>